const CompressionPlugin = require('compression-webpack-plugin');
const path = require('path')
const webpack = require('webpack')
module.exports = {

    // chainWebpack: config => {
    //     config
    //         .plugin('webpack-bundle-analyzer')
    //         .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
    // },
    configureWebpack: (config) => {
        if (process.env.NODE_ENV === 'production') {
            // 为生产环境修改配置...
            config.mode = 'production'
            return {
                plugins: [
                    new CompressionPlugin({
                        test: /\.js$|\.ts$|\.html$|\.css/, //匹配文件名
                        threshold: 10240, //对超过10k的数据进行压缩
                        deleteOriginalAssets: false //是否删除原文件
                    })]
            }
        }
        else {
            // 为开发环境修改配置...
            config.mode = 'development';
        }
    },
    configureWebpack: {
        plugins: [
            new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn/),
        ],
        resolve: {
            alias: {
                '@ant-design/icons-vue$': path.resolve(__dirname, './src/icons/icons.ts')  // 自建的文件的相对路径
            }
        },
    },

    // 生产环境是否生成 sourceMap 文件
    productionSourceMap: false,

}